package com.dinim.object;

import java.util.ArrayList;
import java.util.List;

import com.dinim.math.GeometryUtil;
import com.dinim.matrix.twodimensional.IPoint2D;
import com.dinim.matrix.twodimensional.Vector3;

public class Line2D extends Object2D{

    public Line2D(IPoint2D point1, IPoint2D point2) {
        super(new IPoint2D[]{point1, point2}, new int[]{0,1});
    }

    public Line2D(double x1, double y1, double x2, double y2){
        super(new IPoint2D[]{new Point2D(x1, y1), new Point2D(x2, y2)}, new int[]{0,1});
    }

    public double getLength(){
        return GeometryUtil.getLength(getPoints()[0].getX(), getPoints()[0].getY(), getPoints()[1].getX(), getPoints()[1].getY());
    }
    
    public double getX1(){
        return getPoints()[0].getX();
    }
    
    public double getY1(){
        return getPoints()[0].getY();
    }
    
    public double getX2(){
        return getPoints()[1].getX();
    }
    
    public double getY2(){
        return getPoints()[1].getY();
    }
    
    public void setX1(double x1){
        getPoints()[0].setX(x1);
    }
    
    public void setY1(double y1){
        getPoints()[0].setY(y1);
    }
    
    public void setX2(double x2){
        getPoints()[1].setX(x2);
    }
    
    public void setY2(double y2){
        getPoints()[1].setY(y2);
    }
    
    public IPoint2D getP1(){
        return getPoints()[0];
    }
    
    public IPoint2D getP2(){
        return getPoints()[1];
    }
    
    public Vector3 getNormal(){
        Vector3 normal = new Vector3();
        normal.setX(-(getY2() - getY1()));
        normal.setY(getX2() - getX1());
        return normal;
    }

    
}
